package com.android.volley.http;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.BasicNetwork;
import com.android.volley.toolbox.DiskBasedCache;
import com.squareup.okhttp.OkHttpClient;

import java.io.File;

/**
 * Created by yinzhiqun on 2015/9/14.
 * 创建requestQueue，使用okhttp作为volley的传输层
 */
public class HttpClient {
    private static final String DEFAULT_CACHE_DIR = "volley";

    public static RequestQueue newRequestQueue(Context context) {
        File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

        RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir),
                new BasicNetwork(new OkHttpStack(new OkHttpClient())));

        queue.start();

        return queue;
    }
}
